import config from '@/config'
import { generateVipOrder, generateOrder,payOrder } from '@/api/system/pay'
import {isEmptyString} from "@/utils/common";

const baseUrl = config.baseUrl

const pay = {
    mutations: {

    },

    actions: {
        //生成VIP订单
        GenerateVipOrder({ commit }, data) {
            const price = data.price
            const vipType = data.vipType
            return new Promise((resolve, reject) => {
                generateVipOrder({ price, vipType }).then(res => {
                    resolve(res)
                }).catch(error => {
                    reject(error)
                })
            })
        },
        //生成订单
        GenerateOrder({ commit }, data) {
            let params = {};
            params.consultingId = data.consultingId;
            params.orderTime = data.orderTime;
            params.orderType = data.orderType;
            params.price = data.price;
            params.payType = data.payType;
            if(!isEmptyString(data.teamId)){
                params.teamId = data.teamId
            }
            if(!isEmptyString(data.fillInPhone)){
                params.fillInPhone = data.fillInPhone
            }
            return new Promise((resolve, reject) => {
                generateOrder(params).then(res => {
                    resolve(res)
                }).catch(error => {
                    reject(error)
                })
            })
        },
        //根据id进行支付
        PayOrder({ commit }, data) {
            return new Promise((resolve, reject) => {
                payOrder(data).then(res => {
                    resolve(res)
                }).catch(error => {
                    reject(error)
                })
            })
        }
    }
}

export default pay
